package com.sky.controller.common;

import com.sky.exception.BaseException;
import com.sky.result.Result;
import com.sky.service.common.CommonService;
import com.sky.utils.AliOssUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.util.http.fileupload.FileUploadException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Slf4j
@Api(tags = "通用接口")
@RestController
public class CommonController {
    @Autowired
    private CommonService  commonService;


    @ApiOperation("文件上传")
    @PostMapping("/admin/common/upload")
    public Result<String> upload(@RequestParam("file") MultipartFile file) {
        log.info("文件上传：{}", file);
        try {
            return commonService.upload(file.getBytes(),file.getOriginalFilename());
        } catch (IOException e) {
            throw new BaseException("上传失败"+e.getMessage());
        }
    }
}
